package com.xiaomage.view.draw9

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/6.
 */
class MyView(context: Context):View(context) {
    private lateinit var bitmap:Bitmap
    private var bitmapHeight=0
    private val paint=getPaint()
    private val paint2=getPaint()
    private val paint3=getPaint()
    init {
        bitmap=BitmapFactory.decodeResource(resources,R.drawable.button)
        bitmapHeight=500*bitmap.height/bitmap.width
    }
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,bitmapHeight),paint)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        paint2.colorFilter=LightingColorFilter(0x00ff00,0x000000)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,bitmapHeight),paint2)

        canvas.translate(0f,bitmapHeight+50.toFloat())
        paint3.colorFilter=LightingColorFilter(0xffffff,0x0000f0)
        canvas.drawBitmap(bitmap,null,
                Rect(0,0,500,bitmapHeight),paint3)


    }

    private fun getPaint():Paint{
        val paint=Paint()
        paint.isAntiAlias=true
        paint.strokeWidth=5f
        paint.style=Paint.Style.STROKE
        return paint
    }
}